package com.woniuxy.Customclazz;

import com.woniuxy.Filter.FilterTwo;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * @Author：向天浩
 * @Date：2022/2/15 13:03
 * @Description :自定义类来注册过滤器
 */

@Configuration
public class Filtertwo {
    @Bean
    public FilterRegistrationBean<FilterTwo>FilterTwo(){
        FilterRegistrationBean<FilterTwo> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new FilterTwo());//将我们创建好过滤器放入registrationBean这个对象中
        registrationBean.addUrlPatterns("/*");//拦截哪些请求
        registrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);//设置优先级
        return registrationBean;//加了注解@Bena，这个返回的对象会注册到spring
    }
}
